package product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.ObjectUtils;
import product.domain.SpuImages;
import product.service.SpuImagesService;
import product.mapper.SpuImagesMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author panghu
 * @description 针对表【pms_spu_images(spu图片)】的数据库操作Service实现
 * @createDate 2023-03-04 21:03:08
 */
@Service
public class SpuImagesServiceImpl extends ServiceImpl<SpuImagesMapper, SpuImages>
        implements SpuImagesService {

    @Override
    public void saveImages(Long spuId, List<String> images) {
        if (!ObjectUtils.isEmpty(images)) {
            List<SpuImages> spuImagesList = images.stream().map(image -> {
                SpuImages spuImages = new SpuImages();
                spuImages.setSpuId(spuId);
                spuImages.setImgUrl(image);
                return spuImages;
            }).collect(Collectors.toList());
            this.saveBatch(spuImagesList);
        }
    }
}




